﻿namespace Typps.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Typps;

    using Wilco.CodeHilighter.Engine.SyntaxHighlighting;

    /// <summary>
    /// Currently testing just the 3 main syntax highlighted languages(c#,aspx,css) we'd normally use. 
    /// Let's just take for granted that the others simply work for now until something goes wrong. 
    /// There's no way i'm going to test every language supported :-)
    /// </summary>
    [TestClass]
    public class UnitTestSyntaxHighlighter
    {
        #region Fields

        private TestContext testContextInstance;

        #endregion Fields

        #region Constructors

        public UnitTestSyntaxHighlighter()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #endregion Properties

        #region Methods

        [TestMethod]
        public void GetParsedSourceCode_ASPNET_ColorCoded()
        {
            string source = "<cc1:Editor ID=\"Editor1\" runat=\"server\"></cc1:Editor>";
            SyntaxHighlighter s = new SyntaxHighlighter("ASPX", new HtmlParser(), false, source);
            string result = Helper.TrimAllWhiteSpace(s.GetParsedSourceCode());
            string output = "<divclass=\"linecontent\"><pre><spanstyle=\"color:Blue\">&lt;</span><spanstyle=\"color:Brown\">cc1:Editor</span><spanstyle=\"color:Red\">ID</span>=<spanstyle=\"color:Blue\">&quot;Editor1&quot;</span><spanstyle=\"color:Red\">runat</span>=<spanstyle=\"color:Blue\">&quot;server&quot;</span><spanstyle=\"color:Blue\">&gt;</span><spanstyle=\"color:Blue\">&lt;/</span><spanstyle=\"color:Brown\">cc1:Editor</span><spanstyle=\"color:Blue\">&gt;</span></pre></div>";
            Assert.AreEqual(result, output);

            s.AllowLineNumbering = true;
            result = Helper.TrimAllWhiteSpace(s.GetParsedSourceCode());
            output = "<divclass=\"linenumber\"><pre><spanclass=\"numbers\">0</span></pre></div><divclass=\"linecontent\"><pre><spanstyle=\"color:Blue\">&lt;</span><spanstyle=\"color:Brown\">cc1:Editor</span><spanstyle=\"color:Red\">ID</span>=<spanstyle=\"color:Blue\">&quot;Editor1&quot;</span><spanstyle=\"color:Red\">runat</span>=<spanstyle=\"color:Blue\">&quot;server&quot;</span><spanstyle=\"color:Blue\">&gt;</span><spanstyle=\"color:Blue\">&lt;/</span><spanstyle=\"color:Brown\">cc1:Editor</span><spanstyle=\"color:Blue\">&gt;</span></pre></div>";
            Assert.AreEqual(result, output);
        }

        [TestMethod]
        public void GetParsedSourceCode_CSharp_ColorCoded()
        {
            string source =
            @"private void AddHighlighter(HighlighterBase highlighter)
            {
            this.highlighters.Add(highlighter);
            }";
            SyntaxHighlighter s = new SyntaxHighlighter("C#", new HtmlParser(),false, source);
            string result = Helper.TrimAllWhiteSpace(s.GetParsedSourceCode());
            string output = "<divclass=\"linecontent\"><pre><spanstyle=\"color:Blue\">private</span><spanstyle=\"color:Blue\">void</span>AddHighlighter(HighlighterBasehighlighter){<spanstyle=\"color:Blue\">this</span>.highlighters.Add(highlighter);}</pre></div>";
            Assert.AreEqual(result, output);

            s.AllowLineNumbering = true;
            result = Helper.TrimAllWhiteSpace(s.GetParsedSourceCode());
            output = "<divclass=\"linenumber\"><pre><spanclass=\"numbers\">0</span><br/><spanclass=\"numbers\">1</span><br/><spanclass=\"numbers\">2</span><br/><spanclass=\"numbers\">3</span></pre></div><divclass=\"linecontent\"><pre><spanstyle=\"color:Blue\">private</span><spanstyle=\"color:Blue\">void</span>AddHighlighter(HighlighterBasehighlighter){<spanstyle=\"color:Blue\">this</span>.highlighters.Add(highlighter);}</pre></div>";
            Assert.AreEqual(result, output);
        }

        [TestMethod]
        public void GetParsedSourceCode_CSS_ColorCoded()
        {
            string source = @"<style type=""text/css"">
            .syntaxhighlighter
            {
            float:left;
            background:pink;
            }
            </style>";
            SyntaxHighlighter s = new SyntaxHighlighter("CSS", new HtmlParser(), false, source);
            string result = Helper.TrimAllWhiteSpace(s.GetParsedSourceCode());
            string output = "<divclass=\"linecontent\"><pre>&lt;<spanstyle=\"color:Brown\">style</span><spanstyle=\"color:Brown\">type</span>=&quot;<spanstyle=\"color:Brown\">text</span>/<spanstyle=\"color:Brown\">css</span>&quot;&gt;.<spanstyle=\"color:Brown\">syntaxhighlighter</span>{<spanstyle=\"color:Red\">float</span>:<spanstyle=\"color:Blue\">left</span>;<spanstyle=\"color:Red\">background</span>:<spanstyle=\"color:Blue\">pink</span>;}&lt;/<spanstyle=\"color:Brown\">style</span>&gt;</pre></div>";
            Assert.AreEqual(result, output);
        }

        #endregion Methods
    }
}